package com.iedu.demo.lgq.mapper;

import com.iedu.demo.lgq.entity.TbUserFavorites;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Delete;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserFavoritesMapper {

    // 添加商品到收藏夹
    @Insert("INSERT INTO tb_user_favorites(user_name, item_id, item_title, price,create_time ) VALUES(#{userName}, #{itemId},#{itemTitle},#{price},#{createTime})")
    void addToFavorites(TbUserFavorites favorites);

    // 查询用户收藏的商品
    @Select("SELECT * FROM tb_user_favorites WHERE user_name = #{userName}")
    List<TbUserFavorites> findFavoritesByUserId(String userName);

    // 删除收藏夹中的商品
    @Delete("DELETE FROM tb_user_favorites WHERE user_name = #{userName} AND item_id = #{itemId}")
    void removeFromFavorites(String userName, String itemId);
}
